import {Directive, Output, EventEmitter, DoCheck} from '@angular/core';
import $ from "jquery";

/**
 * Generated class for the InfoRenderListenerDirective directive.
 *
 * See https://angular.io/api/core/Directive for more info on Angular
 * Directives.
 */
@Directive({
    selector: '[info-render-listener]' // Attribute selector
})
export class InfoRenderListenerDirective {
    @Output() rightClickEvent: EventEmitter<any> = new EventEmitter();
    length: number = 0;
    checkTime: boolean = false;

    constructor() {

    }

    ngDoCheck(): void {
        this.changeTag();
    }


    // 改变a标签属性
    changeTag() {
        let zone = this;
        if (!$(".info-bd a").length) {
            zone.rightClickEvent.emit(false);
            return false;
        }
        $(".info-bd a").each(function (e) {
            zone.length++;
            /*
            console.log('render');
            console.log($(this));*/
            if ($(this).attr('href').indexOf('javascript:void(0)') <= -1) {
                $(this).attr({'link': $(this).attr('href')}).attr({'href': 'javascript:void(0);'});
            }

            if (zone.length == $(".info-bd a").length) {
                if (!zone.checkTime) {
                    zone.checkTime = true;
                    console.log('ok')
                    zone.rightClickEvent.emit(true)
                }
                return false;
            }
        })
    }

}
